package com.yaya.generator.dtomain;

import com.yaya.common.object.BaseObject;
import com.yaya.generator.config.DataSourceConfig;
import com.yaya.generator.config.GlobalConfig;
import com.yaya.generator.config.PackageConfig;
import lombok.Getter;
import lombok.Setter;

/**
 * 代码生成器参数传输对象
 */
@Getter
@Setter
public class GeneratorDto extends BaseObject {

  /** 数据库连接 */
  private String url;
  /** 数据库账号 */
  private String username;
  /** 数据库密码 */
  private String password;
  /** 数据库模式 */
//  private String schema;
  /** 作者 */
  private String author;
  /** 输出目录 */
  private String outputDir;
  /** 业务包名 */
  private String parent;
  /** 模块名 */
  private String moduleName;
  /** 表名 */
  private String[] tableNames;

  public static GeneratorDto getParameter() {
    GeneratorDto generatorDto = new GeneratorDto();
    generatorDto.setUrl(DataSourceConfig.URL);
    generatorDto.setUsername(DataSourceConfig.USERNAME);
    generatorDto.setPassword(DataSourceConfig.PASSWORD);
//    generatorDto.setSchema(DataSourceConfig.SCHEMA);
    generatorDto.setAuthor(GlobalConfig.AUTHOR);
    generatorDto.setOutputDir(GlobalConfig.OUTPUT_DIR);
    generatorDto.setParent(PackageConfig.PARENT);
    generatorDto.setModuleName(PackageConfig.MODULE_NAME);
    generatorDto.setTableNames(PackageConfig.TABLE_NAMES);
    return generatorDto;
  }

  public void setParameter() {
    DataSourceConfig.URL = this.getUrl();
    DataSourceConfig.USERNAME = this.getUsername();
    DataSourceConfig.PASSWORD = this.getPassword();
//    DataSourceConfig.SCHEMA = this.getSchema();
    GlobalConfig.AUTHOR = this.getAuthor();
    GlobalConfig.OUTPUT_DIR = this.getOutputDir();
    PackageConfig.PARENT = this.getParent();
    PackageConfig.MODULE_NAME = this.getModuleName();
    PackageConfig.TABLE_NAMES = this.getTableNames();
  }

}
